/**
 * Created by yuming619 on 2016/12/18.
 */
angular.module('mealplan.template', [
    'ngCookies'
])
    .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('mealplan', {
                'abstract': true,
                url: "/mealplan",
                views: {
                    '': {
                        template: '<div ui-view="topbar"></div><div ui-view="main"></div>'
                    },
                    'topbar@mealplan': {
                        templateUrl: template_viewurl + "/topbar.html",
                        controller: 'MealplanTopbarController'
                    },
                    'main@mealplan': {
                        templateUrl: template_viewurl + "/main.html",
                        controller: 'MealplanTemplateController'
                    }
                }
            })
        ;
    }])
    .controller('MealplanTopbarController', ['$scope', '$state', '$cookieStore', function ($scope, $state, $cookieStore) {
        var data = $cookieStore.get('manager_cookie');
        if (data == undefined) {
            alert("登陆已失效，请再次登陆！");
            $state.go('login');
        } else {
            $scope.manager_cookie = data;
            //console.log("this is"+ data.managername);
        }
        // topbar
        if (typeof topbars != 'undefined') {
            $scope.topbars = topbars;
        }

    }])

    .controller('MealplanTemplateController', ['$scope', '$state', '$stateParams', function ($scope, $state, $stateParams) {
        $scope.sidebars = mealplan_sidebars;
        $scope.currentPage = 1;
        $scope.pageSize = 8;
    }])


;
